var menulayer=cc.Layer.extend({
   l:null,
    curObj:null,
    world:null,
    body:null,
   ctor:function(){
       this._super();
   },
   init:function(){
       this._super();
       curObj=cc.Sprite.create(s_obj);
       var winsize=cc.Director.getInstance().getWinSize();
     //  curObj.setPosition(winsize.width/2,winsize.height/2);
       this.addChild(curObj);
       this.world=new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, +10), true); /*tạo 1 world giả lập vật lý
                                                                                   đối số truyền vào là 1 vector2 đại diện gravity  */
      

      var dDraw=Box2D.Dynamics.b2DebugDraw;
      var debugDraw=new dDraw();
       debugDraw.SetSprite(document.getElementsByTagName("canvas")[0].getContext("2d"));
                debugDraw.SetDrawScale(30);
                debugDraw.SetFillAlpha(0.5);
                debugDraw.SetLineThickness(1.0);
                debugDraw.SetFlags(Box2D.Dynamics.b2DebugDraw.e_shapeBit | Box2D.Dynamics.b2DebugDraw.e_jointBit);
                this.world.SetDebugDraw(debugDraw);
                
        //khai báo body       
       var bodyDef=new Box2D.Dynamics.b2BodyDef();
       bodyDef.type=Box2D.Dynamics.b2Body.b2_dynamicBody;
       body=this.world.CreateBody(bodyDef);
       body.SetPosition(cc.p(10,3));
       //khai báo fixture
       var fixDef=new Box2D.Dynamics.b2FixtureDef();
       fixDef.density = 1.0;
       fixDef.friction = 0.5;
       fixDef.restitution = 0.2;
       fixDef.isSensor = true;
       fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape( 1);
       //bind fixture vào body,1 body có thể có nhiều fixture
       body.CreateFixture(fixDef);
       //body.SetUserData(curObj);
      
       this.scheduleUpdate();
   },
   
   update:function(dt){
       //bodyData=body.GetUserData();
      // bodyData.setPosition(body.GetPosition().x,body.GetPosition().y);
       bPos=body.GetPosition();
       //curObj.setPosition(bPos.x,bPos.y);
       cc.log(bPos.y.toString());
       this.world.Step(1/60,10,10);
       this.world.DrawDebugData();
   }
       
       
       
   
});
var menuscene=cc.Scene.extend({
   onEnter:function(){
       this._super();
       var layer=new menulayer();
       layer.init();
       this.addChild(layer);
       this.scheduleUpdate();
   },
  
});
